public class Demo6 {
    public static void main(String[] args) {
        Object locker = new Object();

        Thread thread1 = new Thread(() -> {
            synchronized(locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName());
            }
        });

        Thread thread2 = new Thread(() -> {
            synchronized(locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName());
            }
        });

        Thread thread3 = new Thread(() -> {
            synchronized(locker) {
//                locker.notifyAll();
                locker.notify();
                System.out.println(Thread.currentThread().getName());
            }
            synchronized(locker) {
                locker.notify();
            }
        });

        thread1.start();
        thread2.start();
        thread3.start();
    }
}
